// AuxilaryTable.h
// Author: Sudhir Meher
// Collection of tables that contain cached data (results of previous computaion.)

#ifndef AUX_TABLE_H
#define AUX_TABLE_H
#include"../../SPA_Data_Types.h"

#include <bitset>

using namespace std;

class AuxAffects {
private:
	static AuxAffects *obj;
	INTEGER _numStmts;
	unsigned int *isAffectsAvailable;
	unsigned int *isAffects;
	//bitset *b2;
	size_t bitLength;
	unsigned int _c;
	int bitPosition;
	unsigned int cacheSize;

	BOOLEAN getBit( unsigned int i, int bitPos ) {
		//bitPos = bitLength-bitPos;
		i = (i >> bitPos);
		if( (i&1) == 1 )
		return true;
		else return false;
	};

	BOOLEAN setBit ( unsigned int &i, int bitPos ) {
		_c = 1;
		//_c = (_c << (bitLength - bitPos));
		_c = (_c << (bitPos));
		if( bitPos < (_numStmts*_numStmts) ){
			i =  ( i | _c );
			return STATUS_Success;
		} else
			return STATUS_Failure;
	};

	unsigned int index;

	AuxAffects();
public:
	static AuxAffects* getInstance();

	// sets the number of assignment statements in the source file.
	// Warning: this function has to be called only once.
	void initialize ( INTEGER _num_Stmts );

	// if cached data is available, returns ture, else false
	BOOLEAN isAuxAffectsAvailable ( STATEMENT_INDEX stmt1, STATEMENT_INDEX stmt2 );

	// returns the stored cached Affects result.
	// true if statement_1 affects statement_2, else false
	BOOLEAN affects(STATEMENT_INDEX stmt1, STATEMENT_INDEX stmt2 );

	STATUS setAffects ( STATEMENT_INDEX statement_1, STATEMENT_INDEX statement_2 );
};


#endif